package rullekake.facade;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import rullekake.entities.Course;
import rullekake.entities.Faculty;
import rullekake.entities.StudyProgram;

/**
 * Utvider AbstractFacade for Course.
 * Tar seg av peristence for Course-objekter
 *
 */

@Stateless
public class StudyProgramFacade extends AbstractFacade<StudyProgram> {
    @PersistenceContext(unitName = "SystemeringPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public StudyProgramFacade() {
        super(StudyProgram.class);
    }

    /**
     * Finner alle studieprogram som er knytt til et gitt fakultet.
     * @param fakultet
     * @return liste med studieprogram
     */

    public List<Course> findStudyProgramsByFaculty(Faculty faculty) {
        javax.persistence.Query q = getEntityManager().createNamedQuery("StudyProgram.findByFaculty");
        q.setParameter("faculty", faculty);
        return q.getResultList();
    }
}
